package com.imti.mall.sale.mapper;

import com.imti.mall.model.pms.pojo.PmsProductCategory;
import com.imti.mall.model.sms.pojo.SmsHomeBrand;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.jdbc.SQL;

public class SmsHomeBrandMapper {

    /**
     * 查询品牌推荐列表
     */
    public String findBrand(final SmsHomeBrand smsHomeBrand){
        return new SQL(){
            {
                SELECT(" id,brand_id,brand_name,recommend_status,sort");
                FROM(" sms_home_brand");
                StringBuffer sb=new StringBuffer();
                if(smsHomeBrand!=null){
                    if(smsHomeBrand.getBrandName()!=null){
                        sb.append(" and brand_name LIKE concat('%',#{brandName},'%')");
                    }
                    if(smsHomeBrand.getRecommendStatus()!=null){
                        sb.append(" and recommend_status=#{recommendStatus}");
                    }
                }
                WHERE(" 1=1 "+sb.toString());
                ORDER_BY(" sort desc");
            }
        }.toString();
    }

    /**
     * 查询品牌推荐列表的总条数
     */
    public String countFindBrand(final SmsHomeBrand smsHomeBrand){
        return new SQL(){
            {
                SELECT(" count(*)");
                FROM(" sms_home_brand");
                StringBuffer sb=new StringBuffer();
                if(smsHomeBrand!=null){
                    if(smsHomeBrand.getBrandName()!=null){
                        sb.append(" and brand_name LIKE concat('%',#{brandName},'%')");
                    }
                    if(smsHomeBrand.getRecommendStatus()!=null){
                        sb.append(" and recommend_status=#{recommendStatus}");
                    }
                }
                WHERE(" 1=1 "+sb.toString());
            }
        }.toString();
    }



    /**
     * 修改品牌推荐
     * @param smsHomeBrand
     * @return
     */
    public String updateSmsHomeBrand(final SmsHomeBrand smsHomeBrand){
        return new SQL(){
            {
                UPDATE(" sms_home_brand ");
                if(smsHomeBrand.getBrandId()!=null){
                    SET(" brand_id=#{brandId} ");
                }
                if(smsHomeBrand.getBrandName()!=null){
                    SET(" brand_name=#{brandName} ");
                }
                if(smsHomeBrand.getRecommendStatus()!=null){
                    SET(" recommend_status=#{recommendStatus} ");
                }
                if(smsHomeBrand.getSort()!=null){
                    SET(" sort=#{sort} ");
                }

                WHERE(" id=#{id} ");
            }
        }.toString();
    }


}
